//
//  TZZhuceNextcontroller.m
//  XMLYFM
//
//  Created by dllo on 16/1/3.
//  Copyright © 2016年 zzl. All rights reserved.
//

#import "TZZhuceNextcontroller.h"
#import <SMS_SDK/SMSSDK.h>
#import <SMS_SDK/SMSSDKCountryAndAreaCode.h>
#import <SMS_SDK/SMSSDK+DeprecatedMethods.h>
#import <SMS_SDK/SMSSDK+ExtexdMethods.h>
#import "TZzhuceinfo.h"


@interface TZZhuceNextcontroller ()
@property(nonatomic,retain)NSTimer* timer2;
@end
static int count = 0;
@implementation TZZhuceNextcontroller

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = [UIColor whiteColor];
    self.codeLabeL.layer.borderColor = [UIColor grayColor].CGColor;
    self.codeLabeL.layer.borderWidth = 1;
    
    self.timer2 = [NSTimer scheduledTimerWithTimeInterval:1
                                                       target:self
                                                     selector:@selector(updateTime)
                                                     userInfo:nil
                                                      repeats:YES];
    self.phoneLabel.text = self.phoneNumber;
}


-(void)updateTime
{
    
    count++;
    if (count >= 60)
    {
        [_timer2 invalidate];
        return;
    }
    //NSLog(@"更新时间");
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@%i%@",NSLocalizedString(@"timelablemsg", nil),60-count,NSLocalizedString(@"second", nil)];
    
    
    
    
}
- (IBAction)NextAction:(UIButton *)sender {
    
    [SMSSDK commitVerificationCode:self.codeTextField.text phoneNumber:self.phoneNumber zone:@"86" result:^(NSError *error) {
        
        
        
        
        
        if (!error) {
            
           

            
            TZzhuceinfo *INFO = [[TZzhuceinfo alloc]init];
            INFO.phoneNumber = self.phoneNumber;
            
            [self.navigationController pushViewController:INFO animated:YES];
        
        }
        else
        {
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入正确的验证码" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alertC animated:YES completion:^{
                
                
            }];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                
                [self.navigationController dismissViewControllerAnimated:YES completion:^{
                    
                    
                }];
                
            }];
            
            [alertC addAction:action];
        }

        
    }];

    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
